package com.tiantianyuegou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantianyuegou.R;
import com.tiantianyuegou.model.TicketModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huyang on 2016/1/11 0011.
 */
public class RedPageAdapter extends BaseAdapter {

    private Context context;
    private List<TicketModel> data;


    public RedPageAdapter(Context context) {
        this.context = context;
        data =new ArrayList<>();
    }

    public RedPageAdapter(Context context, List<TicketModel> data) {
        this.context = context;
        this.data = data;
    }

    public void setData(List<TicketModel> data) {
        this.data.clear();
        this.data.addAll(data);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent) {
        TicketModel model=data.get(position);
        final ViewHolder holder;
        if (converView==null){
            converView= LayoutInflater.from(context).inflate(R.layout.item_list_redpag,null);
            holder=new ViewHolder();
            holder.tv_count= (TextView) converView.findViewById(R.id.tv_jiner);
            holder.tv_usecount= (TextView) converView.findViewById(R.id.tv_rule);
            holder.tv_starttime= (TextView) converView.findViewById(R.id.tv_starttime);
            holder.tv_endtime= (TextView) converView.findViewById(R.id.tv_endtime);
            converView.setTag(holder);
        }else{
            holder= (ViewHolder) converView.getTag();
        }
        holder.tv_count.setText(model.getTtMoney());
        holder.tv_usecount.setText("满"+model.getTtTop()+"元使用");
        holder.tv_starttime.setText(model.getTtStart()+"-");
        holder.tv_endtime.setText(model.getTtEnd());


        return converView;
    }
    class ViewHolder{
        TextView tv_count,tv_usecount,tv_starttime,tv_endtime;
    }
}
